import {
    React,
    useEffect
} from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import {
    BrowserRouter,
    Route,
    Routes,
    useNavigate,
    Navigate
} from "react-router-dom";
import Login from "./open-type/login";
import Home from "./component/home";
import BannerActive from "./component/banner/BannerActive";
import BannerHome from "./component/banner/BannerHome";
import ProList from "./component/pro/ProList";
import ProSearch from "./component/pro/ProSearch";
import UserList from "./component/account/UserList";
import AdminList from "./component/account/AdminList";
import Setting from "./component/setting/index";
import OrderFormList from "./component/orderform/orderFormList";
import CartList from "./component/cart/CartList";
import Line from "./component/echarts/Line";
import Pie from "./component/echarts/Pie";
import AddAdmin from "./component/account/addAdmin";
import Map from "./component/map/Map";
import RichText from "./component/richtext/md-editor/index";

const root = ReactDOM.createRoot(document.getElementById('root'));

//路由重定向
// const Height1 = (props) => {
//     const Navigate = useNavigate()
//     useEffect(() => {
//         Navigate(props.to)
//     })
//     // console.log(props);
// }
const status = localStorage.getItem("token") ? true : false
root.render(
    <>
      <BrowserRouter>
      < Routes >
            <Route path='/' element={<Navigate to="/login"> </Navigate>} ></Route>
            <Route path='/login'
                element={<Login > </Login>}></Route >
            <Route path='/' element={status ? < App > </App> : <Login></Login >} >
                <Route path='/home' element={<Home> </Home>}></Route >
                <Route path='/banner' >
                    <Route path='home' element={<BannerHome> </BannerHome>}> </Route >
                    <Route path='active' element={<BannerActive > </BannerActive>}></Route >
                </Route> <Route path='/pro' >
                    <Route Route path='list' element={< ProList > </ProList>}></Route >
                    <Route path='search' element={<ProSearch > </ProSearch>}></Route >
                </Route> < Route path='/account' >
                    <Route path='userlist' element={< UserList > </UserList>}></ Route>
                    <Route path='adminlist' element={< AdminList > </AdminList>}></Route>
                    <Route path='add' element={<AddAdmin></AddAdmin>} ></Route>
                </Route> <Route path='/orderfrom' >
                    <Route path='orderfromlist' element={< OrderFormList > </OrderFormList>}></Route>
                </Route> < Route path='/cart' >
                    <Route path='list' element={< CartList > </CartList>}></Route >
                </Route> <Route path='/echarts' >
                    <Route path="line" element={< Line > </Line>}></Route>
                    <Route path="pie" element={< Pie > </Pie>}></Route >
                </Route>
                <Route path='/map' element={<Map> </Map>}></Route >
                <Route path='/richtext' element={<RichText></RichText>}></Route>
                <Route path='/setting' element={<Setting> </Setting>}></Route >
            </Route>
        </Routes>
      </BrowserRouter>
    </>
);